package ly.registry.entity;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class ScheduleTime {

    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss");

    //上个任务开始时计时2秒触发
    @Scheduled(fixedRate = 2000)
    public void fixedRate(){
        System.out.println("当前时间是  "+DATE_FORMAT.format(new Date()));

    }
    //上个任务结束时2秒触发
    @Scheduled(fixedDelay =2000 )
    public void fixedDelay(){
        System.out.println("当前时间是  "+DATE_FORMAT.format(new Date()));

    }
    //自定义规则 每天22:30-23:00没分钟执行一次
    @Scheduled(cron = "0 0/1 22-23 * * ?")
    public void cron(){
        System.out.println("当前时间是  "+DATE_FORMAT.format(new Date()));
    }
}
